def merge_intervals(intervals):
    """先合并重叠区间，再查找目标是否在区间内"""
    if not intervals:
        return []
    # 按区间起点排序
    intervals.sort(key=lambda x: x[0])
    merged = [intervals[0]]
    for current in intervals[1:]:
        last = merged[-1]
        # 重叠则合并
        if current[0] <= last[1]:
            merged[-1] = [last[0], max(last[1], current[1])]
        else:
            merged.append(current)
    return merged

def is_in_intervals(merged, target):
    """二分查找目标是否在合并后的区间内"""
    left, right = 0, len(merged) - 1
    while left <= right:
        mid = (left + right) // 2
        start, end = merged[mid]
        if start <= target <= end:
            return True
        elif target < start:
            right = mid - 1
        else:
            left = mid + 1
    return False

# 测试
intervals = [[1,3],[2,6],[8,10],[15,18]]
merged = merge_intervals(intervals)  # 合并为[[1,6],[8,10],[15,18]]
print(is_in_intervals(merged, 5))   # 输出：True（在[1,6]内）
print(is_in_intervals(merged, 7))   # 输出：False